package com.qf.medicaldoctoradmin.healthMonitor.drugInfo.controller;

import com.qf.common.common.R;
import com.qf.common.entity.DrugInfo;
import com.qf.medicaldoctoradmin.healthMonitor.drugInfo.param.DrugInfoParam;
import com.qf.medicaldoctoradmin.healthMonitor.drugInfo.service.DrugFavoriteService;
import com.qf.medicaldoctoradmin.healthMonitor.drugInfo.service.DrugInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "药品相关API")
@RestController
@CrossOrigin
@RequestMapping("/drugInfo")
public class DrugInfoController {
    @Resource
    private DrugInfoService drugInfoService;

    @Resource
    private DrugFavoriteService drugFavoriteService;

    @ApiOperation(value = "收藏药品相关文章", notes = "收藏药品相关文章，1为收藏状态，0为取消收藏状态")
    @GetMapping("/favorite")
    public R like(Integer drugId) {
        drugFavoriteService.favoriteInfo(drugId);
        return R.ok("操作成功");
    }

    @ApiOperation(value = "查询已收藏药品信息列表", notes = "根据收藏状态查询药品数据信息")
    @GetMapping("/getFavorite")
    public R pageInfo() {
        List<DrugInfo> list = drugFavoriteService.getFavoriteList();
        return R.ok(list);
    }

    @ApiOperation(value = "模糊查询药品信息列表", notes = "根据药品名，模糊查询药品数据信息")
    @GetMapping("/page")
    public R pageInfo(String drugName) {
        List<DrugInfo> list = drugInfoService.getList(drugName);
        return R.ok(list);
    }
}
